package com.leetcode.partition7;

import java.util.Arrays;

/**
 * @author `RKC`
 * @date 2021/8/25 9:00
 */
public class LC674最长连续递增序列 {

    public static int findLengthOfLCIS(int[] nums) {
        return dynamicProgramming(nums);
    }

    public static void main(String[] args) {
        int[] nums = {1, 3, 2, 6, 7};
        System.out.println(findLengthOfLCIS(nums));
    }

    private static int greedy(int[] nums) {
        int count = 0, answer = count;
        if (nums.length == 1) return 1;
        if (nums[1] > nums[0]) count++;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] > nums[i - 1]) count++;
            else count = 1;
            answer = Math.max(answer, count);
        }
        return answer;
    }

    private static int dynamicProgramming(int[] nums) {
        int[] dp = new int[nums.length];
        int answer = 0;
        for (int i = 1; i < nums.length; i++) {
            // 如果nums[i]>nums[i-1]，那么以i为结尾的数组的连续递增子序列长度一定等于nums[i-1]+1；
            // 因为要求连续递增序列，所以只需要比较nums[i]和nums[i-1]，而不需要nums[i]和nums[j]
            if (nums[i] > nums[i - 1]) {
                dp[i] = dp[i - 1] + 1;
                answer = Math.max(answer, dp[i]);
            }
        }
        System.out.println(Arrays.toString(dp));
        return answer + 1;
    }
}
